{% extends "base_generic.html" %}

{% block title %}Authors - Local Library{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
  <div>
    <h1><i class="bi bi-people"></i> Authors</h1>
    <p class="text-muted">Browse our collection of authors</p>
  </div>
  
  {% if perms.catalog.add_author %}
    <a href="{% url 'author-create' %}" class="btn btn-primary">
      <i class="bi bi-plus"></i> Add Author
    </a>
  {% endif %}
</div>

{% if author_list %}
  <div class="row g-4">
    {% for author in author_list %}
      <div class="col-md-6 col-lg-4">
        <div class="card h-100">
          <div class="card-body">
            <h5 class="card-title">
              <a href="{{ author.get_absolute_url }}" class="text-decoration-none">
                {{ author.first_name }} {{ author.last_name }}
              </a>
            </h5>
            
            <div class="mb-3">
              {% if author.date_of_birth %}
                <p class="card-text mb-1">
                  <small class="text-muted">
                    <i class="bi bi-calendar"></i> Born: {{ author.date_of_birth }}
                  </small>
                </p>
              {% endif %}
              
              {% if author.date_of_death %}
                <p class="card-text mb-1">
                  <small class="text-muted">
                    <i class="bi bi-calendar-x"></i> Died: {{ author.date_of_death }}
                  </small>
                </p>
              {% endif %}
            </div>
            
            <div class="d-flex justify-content-between align-items-center">
              <small class="text-muted">
                Books: {{ author.book_set.count }}
              </small>
              {% if perms.catalog.change_author %}
                <div class="btn-group" role="group">
                  <a href="{% url 'author-update' author.pk %}" class="btn btn-outline-primary btn-sm">
                    <i class="bi bi-pencil"></i>
                  </a>
                  <a href="{% url 'author-delete' author.pk %}" class="btn btn-outline-danger btn-sm">
                    <i class="bi bi-trash"></i>
                  </a>
                </div>
              {% endif %}
            </div>
          </div>
          <div class="card-footer bg-transparent">
            <a href="{{ author.get_absolute_url }}" class="btn btn-primary btn-sm w-100">
              View Details
            </a>
          </div>
        </div>
      </div>
    {% endfor %}
  </div>
{% else %}
  <div class="text-center py-5">
    <i class="bi bi-people display-1 text-muted"></i>
    <h3 class="mt-3">No authors found</h3>
    <p class="text-muted">There are no authors in the library yet.</p>
    {% if perms.catalog.add_author %}
      <a href="{% url 'author-create' %}" class="btn btn-primary">
        <i class="bi bi-plus"></i> Add First Author
      </a>
    {% endif %}
  </div>
{% endif %}

{% endblock %} 